package trabajoISW2.tests;

import java.util.LinkedList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import trabajoISW2.domain.exceptions.WrongIdException;
import trabajoISW2.domain.exceptions.WrongNameException;
import trabajoISW2.domain.implementations.Author;
import trabajoISW2.domain.implementations.Book;



public class AuthorTestSuite extends SuperTest{
	
	Author a;
	List<Book> lb; 
	Book b1;
	Book b2;
	SuperTest st;
	
	@Before
	public void setup(){
		//a = new Author();
		lb = new LinkedList<Book>();
		st = new SuperTest();
		st.inicializa();
		a = st.author1;
		
	}
	
	//Tests sobre el metodo setAuthorId.
	
	@Test 
	public void testSetAuthorId1(){
		a.setAuthorId(0);
		a.setAuthorId(Integer.MAX_VALUE);
		a.setAuthorId(Integer.MAX_VALUE - 1);
		a.setAuthorId(1);
		
	}
	
	
	@Test(expected = WrongIdException.class)
	public void testSetAuthorId2(){
		a.setAuthorId(-1);
		
	}
	
	@Test(expected = WrongIdException.class)
	public void testSetAuthorId3(){
		a.setAuthorId(Integer.MIN_VALUE);
	}
	
	@Test(expected = WrongIdException.class)
	public void testSetAuthorId4(){
		a.setAuthorId(Integer.MIN_VALUE + 1);
	}
	
	//Test sobre el metodo setName
	@Test
	public void testSetName1(){
		a.setName("Juan");
		a.setName("Jos� Juan");
	}
	
	@Test (expected = WrongNameException.class)
	public void testSetName2(){
		a.setName(null);
	}
	
	@Test (expected = WrongNameException.class)
	public void testSetName3(){
		a.setName("");
	}
	
	//tests sobre el método  setSurname
	@Test
	public void testSetSurname1(){
		a.setSurname("Gonzalez");
		a.setName("Gonzalez-Gordo");
		
	}
	
	@Test (expected = WrongNameException.class)
	public void testSetSurname2(){
		a.setSurname(null);
	}
	
	@Test (expected = WrongNameException.class)
	public void testSetSurname3(){
		a.setSurname("");
	}
	
	@Test
	public void testSetBooks1(){
		lb.add(book1);
		a.setBooks(lb);
		lb.add(book2);
		a.setBooks(lb);
		
	}
	
	@Test
	public void testSetBooks2(){
		a.setBooks(lb);
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void testSetBooks3(){
		a.setBooks(null);
	}
	 
//Pruebas sobre el método addBook
	
	@Test 
	public void testAddBook1(){
		a.addBook(st.book1);
		a.addBook(st.book2);
		
		
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void testAddBook2(){
		a.addBook(null);
	}
	
	//Pruebas sobre removeBook
	
	@Test
	public void testRemoveBook1(){
		a.addBook(st.book1);
		a.addBook(st.book2);
		a.removeBook(st.book2);
		a.removeBook(st.book1);
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void testRemoveBook2(){
		a.removeBook(null);
	}
	
	
	
}
 